home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / test / test.c < prev    next >
Text File  |  1993-12-06  |  4KB  |  132 lines

  1. /**
  2.  ** TEST.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24.  
  25. #include "test.h"
  26. #include <string.h>
  27.  
  28. #ifdef __TURBOC__
  29. extern long clock(void);
  30. #endif
  31.  
  32. #ifdef __GNUC__
  33. extern long rawclock(void);
  34. #define clock() rawclock()
  35. #endif
  36.  
  37. void print_stats(int clockdiff,int numwrites)
  38. {
  39.     char buff[200];
  40.     double tdiff = (double)clockdiff / 18.2;
  41.     double pixels = (double)GrSizeX() * (double)GrSizeY();
  42.     double bytes = (double)GrPlaneSize(GrSizeX(),GrSizeY());
  43.  
  44.     sprintf(buff,
  45.        "  %d screen writes in %.2f seconds\n",
  46.        numwrites,
  47.        tdiff
  48.     );
  49.     strcat(exit_message,buff);
  50.     sprintf(buff,
  51.        "  speed = %.2f Mpixels/second\n",
  52.        (pixels * numwrites) / tdiff / 1.0e+06
  53.     );
  54.     strcat(exit_message,buff);
  55.     switch(GrAdapterType()) {
  56.       case GR_HERC:
  57.       case GR_EGA:
  58.       case GR_VGA:
  59.         sprintf(buff,
  60.         "  video RAM write speed = %.2f Mbytes/second\n",
  61.         (bytes * numwrites) / tdiff / 1.0e+06
  62.         );
  63.         break;
  64.       default:
  65.         strcpy(buff,"  accelerated video\n");
  66.         break;
  67.     }
  68.     strcat(exit_message,buff);
  69. }
  70.  
  71. TESTFUNC(test1)
  72. {
  73.     long start;
  74.     int  ii,results[16],res2[16];
  75.     GrContext *xxx;
  76.  
  77.     sprintf(exit_message,
  78.         "GRAPHICS MODE:\n  width  = %d\n  height = %d\n  colors = %d\n",
  79.         GrSizeX(),
  80.         GrSizeY(),
  81.         GrNumColors()
  82.     );
  83.     while(kbhit()) getkey();
  84.     ii = 0;
  85.     start = clock();
  86.     while(!kbhit() && (ii < 50)) GrClearContext(++ii & 15);
  87.     strcat(exit_message,"\nVIDEO SPEED TEST:\n");
  88.     print_stats((int)(clock() - start),ii);
  89.     while(kbhit()) getkey();
  90.  
  91.     if((GrNumColors() == 256) && (GrAdapterType() == GR_VGA)) {
  92.         extern GrContext _GrContext;
  93.         GrPlot(0,0,0);
  94.         _GrContext.gc_onscreen = 0;
  95.         ii = 0;
  96.         start = clock();
  97.         while(!kbhit() && (ii < 50)) GrClearContext(++ii & 15);
  98.         strcat(exit_message,"\n256 COLOR SPEED NOT USING PLANE MODE:\n");
  99.         print_stats((int)(clock() - start),ii);
  100.         GrSetContext(NULL);
  101.         while(kbhit()) getkey();
  102.     }
  103.  
  104.     GrClearScreen(GrBlack());
  105.     drawing(0,0,GrSizeX(),GrSizeY(),GrWhite(),GrBlack());
  106.     getkey();
  107.  
  108.     GrClearScreen(GrBlack());
  109.     xxx = GrCreateContext(100,100,NULL,NULL);
  110.     for(ii = 0; ii < 16; ii++) {
  111.         GrPlot(100+5*ii,100,ii);
  112.         results[ii] = GrPixel(100+5*ii,100);
  113.         GrBitBlt(xxx,3+ii,1,NULL,100+5*ii,100,100+5*ii,100,GrWRITE);
  114.         GrSetContext(xxx);
  115.         res2[ii] = GrPixel(3+ii,1);
  116.         GrSetContext(NULL);
  117.     }
  118.  
  119.     strcat(exit_message,"\nREAD/WRITE TEST:\n");
  120.     for(ii = 0; ii < 16; ii++) {
  121.         char buff[100];
  122.         sprintf(buff,"  written pixel: 0x%02x, read back 0x%02x (0x%02x)\n",
  123.         ii,
  124.         results[ii],
  125.         res2[ii]
  126.         );
  127.         strcat(exit_message,buff);
  128.     }
  129.     getkey();
  130. }
  131.  
  132.